﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using T.FAS.Runtime.Metadata.Entity.DataModel;

namespace T.FAS.Runtime.Metadata.Entity.Page
{
    public class DependencyAction
    {
        /// <summary>
        /// MetaData
        /// </summary>
        public ActionMetaData MetaData { get; set; }
        /// <summary>
        /// ActionType
        /// </summary>
        public ActionType ActionType { 
            get {
                return ActionType.Action; 
            }
        }
        /// <summary>
        /// DataSourceType
        /// </summary>
        public string DataSourceType
        {
            get
            {
                return "Action";
            }
        }
        private List<ViewModelParameter> _Parameters = null;
        /// <summary>
        /// Parameters
        /// </summary>
        public List<ViewModelParameter> Parameters
        {
            get
            {
                if (_Parameters == null || _Parameters.Count <= 0)
                {
                    var parameters = new List<ViewModelParameter>();
                    var queryParams = MetaData.MethodParams.Where(t => t.ParamType == ParamType.In).ToList();
                    foreach (var param in queryParams)
                    {
                        parameters.Add(new ViewModelParameter
                        {
                            ID = Guid.NewGuid().ToString(),
                            Code = param.Code,
                            DataType = param.SysDataType.ToString(),
                            Name = param.Name,
                            Value = param.DefaultValue,
                        });
                    }
                    _Parameters = parameters;
                }
                return _Parameters;
            }
        }
        private string _DisplayName = null;
        /// <summary>
        /// DisplayName
        /// </summary>
        public string DisplayName
        {
            get
            {
                if (string.IsNullOrEmpty(_DisplayName))
                {
                    _DisplayName = $"Action.{MetaData.MetaDataCode}({string.Join(",", Parameters.Select(t => t.Code))})";
                }
                return _DisplayName;
            }
        }
    }
}
